package com.example.studyproject.utils;

import java.util.HashMap;
import java.util.Map;

/**
 * @program: StudyProject
 * @description: 统一格式
 * @author: kangwei
 * @create: 2023-03-14 14:36
 **/
public class ResponseUtils {

    /**
     * 成功返回
     *
     * @param code
     * @param msg
     * @param data
     * @return
     */
    public static Map<String, Object> success(String code, String msg, Object data) {
        Map<String, Object> successMap = new HashMap<>();
        successMap.put("code", code);
        successMap.put("msg", msg);
        successMap.put("data", data);
        return successMap;
    }

    public static Map<String, Object> success(Object data) {
        Map<String, Object> successMap = new HashMap<>();
        successMap.put("code", 200);
        successMap.put("msg", "");
        successMap.put("data", data);
        return successMap;
    }

    /**
     * 失败返回
     *
     * @param code
     * @param msg
     * @return
     */
    public static Map<String, Object> error(String code, String msg) {
        Map<String, Object> errorMap = new HashMap<>();
        errorMap.put("code", code);
        errorMap.put("msg", msg);
        return errorMap;
    }
}
